package com.xuchao.yao_jz.web;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.xuchao.yao_jz.dto.UserDto;
import com.xuchao.yao_jz.entity.Users;
import com.xuchao.yao_jz.service.IUsersService;
import com.xuchao.yao_jz.vo.ResultEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Mht
 * @since 2020-03-16
 */
@RestController
@RequestMapping("/users")
@Slf4j
public class UsersController {

    @Autowired
    IUsersService usersService;

    @RequestMapping("/getUserMessage")
    public ResultEntity getUserMessage(UserDto userDto){
        Wrapper wrapper = new EntityWrapper();
        if (userDto.getId() != null){
            wrapper.eq("id",userDto.getId());
            Users users = usersService.selectOne(wrapper);
            return ResultEntity.ok(users);
        }
        List list = usersService.selectList(wrapper);

        return  ResultEntity.ok(list);
    }

    @RequestMapping("/addUsers")
    public ResultEntity addUsers(UserDto userDto){
        Users users = new Users();
        BeanUtils.copyProperties(userDto,users);
        boolean insert = usersService.insert(users);

        return ResultEntity.ok("添加患者成功");
    }


}
